<style lang="scss" >
  @import "../../utils/base.scss";

  .ivu-spin-fix .ivu-spin-main {
    top: 60px;
  }
  .ivu-badge-count{
    z-index: 1;
  }
  .customTooltip * {
    color: #4a4a4a;
    font-size: 18px
  }

  .customTooltip .introjs-tooltip-title {
    color: #0a41c9;
  }
</style>
<template>
  <div ref='base' id="base" class="quest_content"  >
    <stepInfo ref="stepInfo" v-model="stepTitleId" :ishidden="ishidden" :stepTitle="stepTitle">
      <template slot="content">
        <div style="position: relative;">
          <component v-show="stepTitleId === 0" ref="projectInfo" :is="'projectInfo'" :ifedit="ifedit" :reqId="reqId"
            :ProleList="roleList" :Papply="applyinfo" :PprojectList="projectList" :editPeople="false" :isStepAll="false"></component>
          <component v-show="stepTitleId === 1" :key="toolKey + 1" id="resoureceInfo" ref="resoureceInfo"
            :is="'resoureceInfo'" :isEdit="isEdit" :ifedit="ifedit" :tempResource="tempResource" :Papply="applyinfo"
            :Presources="resourcesInfo"></component>
          <component v-show="stepTitleId === 2" :key="toolKey" ref="toolInfo" :allServerList="allServerList"
            :is="'toolInfo'" :isEdit="isEdit" :reqId="reqId" :ifedit="ifedit" :Papply="applyinfo" :tempTool="tempTool"
            :Ptool="toolInfo"></component>
          <component v-show="stepTitleId === 3" ref="server_model" :is="'server_model'" :isEdit="isEdit"
            :allServerList="allServerList" :toolInfo="toolInfo" v-model="seversList" :ifedit="ifedit" :Papply="applyinfo"
            :isApply="true"></component>
          <!-- <component v-if="stepTitleId === 4" ref="dataInfo" :is="'dataInfo'" :seversList="seversList"
            :toolList="toolInfo.toolList" :apiServiceList="toolInfo" :ifedit="ifedit" :Papply="applyinfo"></component> -->
            <div v-show="stepTitleId === 4">
<!--             <div class="qheader" :style=" {borderBottom: '0px'}">
              <p>使用人信息</p>
            </div>
            <component ref="usePeople" :is="'usePeople'" v-model="applyinfo.account.people" :ifedit="true"
              :peopleList="applyinfo.account.peopleList" :isShow="true"></component> -->
              <div class="qheader" :style=" {borderBottom: '0px'}">
                <p>关联的账号信息</p>
              </div>
              <component v-model="account" ref="account" :is="'account'" :isEdit="false" :ifedit="ifedit" :reqId="reqId" style="width:93.5%;position:relative;left:4%"></component>
          </div>
          <component v-show="stepTitleId === 5" ref="file" :is="'file'" :ifedit="ifedit" :filesList="filesList"
            v-model="applyinfo.files"></component>

          <div v-show="stepTitleId === 6" ref="allInfo">
            <component ref="overview" :is="'overview'" :key="toolKey +1" :apiServiceList="toolInfo"
              :seversList="seversList" :toolList="toolInfo.toolList" :ifedit="ifedit" :applyinfo="applyinfo"
              :tempTool="tempTool" :reqId="reqId" :roleList="roleList" :projectList="projectList"
              :resourcesInfo="resourcesInfo" :isEdit="isEdit" :toolInfo="toolInfo" :filesList="filesList" :accountList="account"></component>
          </div>
          <Spin size="large" fix v-if="lodingOver"></Spin>
        </div>
      </template>
    </stepInfo>
  </div>
</template>
<script>
  import ajax from "../../ajax_util"
  import Axios from 'axios'
  import projectInfo from './settledin_test/projectInfo'
  import resoureceInfo from './settledin_test/resourceInfo'
  import toolInfo from './settledin_test/toolInfo'
  import dataInfo from './settledin_test/dataInfo'
  import server_model from './apply_model/server_model.vue'
  // import account from './settledin_test/account'
  import account from './settledin_test/accounttemplate.vue'
  import usePeople from './settledin_test/usePeople'
  import file from './settledin_test/file'
  import notice from '../../base/notice'
  import PDFJs from '../../plugins/PDFJs.js'
  import printModel from './print/print_model'
  import stepInfo from './step_info.vue'
  import excel from "../../utils/excel";
  import overview from "./settledin_test/overview.vue"

  export default {
    name: "apply",
    components: {
      projectInfo,
      resoureceInfo,
      toolInfo,
      dataInfo,
      account,
      file,
      notice,
      printModel,
      stepInfo,
      usePeople,
      server_model,
      overview
    },
    data() {
      const validateEntryEndTime = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请选择结束时间'));
        } else {
          if (this.applyinfo.projectInfo.entryStartTime === '') {
            callback(new Error('请选择开始时间'));
          } else if (this.applyinfo.projectInfo.entryStartTime.getTime() > value.getTime()) {
            callback(new Error('结束时间不能小于开始时间'));
          } else {
            callback()
          }
        }
      };

      return {
        allServerList: [],
        toolKey: 0,
        lodingOver: false, //是否加载完成
        test2: false,
        stepPage: "projectInfo",
        stepTitleId: 0,
        serviceType: "entry_v2",
        stepTitle: [{
            id: 0,
            name: "基本信息",
          },
          {
            id: 1,
            name: "资源申请",
          },
          {
            id: 2,
            name: "工具申请",
          },
          {
            id: 3,
            name: "服务器申请",
          },
          {
            id: 4,
            name: "账号申请",
          },
          {
            id: 5,
            name: "附件",
          },
          {
            id: 6,
            name: "概览",
          }
        ],

        showFileMould: false,
        httpHeader: {
          Authorization: this.$store.state.token
        },
        dataInfoEdit: 0,
        // ifedit: this.isedit,
        disabledDate: {
          disabledDate(date) {
            return date && date.valueOf() < new Date().getTime();
          }
        },
        projectInfoValidate: {
          roleId: [{
            required: true,
            type: 'number',
            message: '请选择租户角色',
            trigger: 'change'
          }, ],
          projectId: [{
            required: true,
            type: 'number',
            message: '请选择关联项目',
            trigger: 'change'
          }, ],
          entryStartTime: [{
            required: true,
            type: 'date',
            message: '请选择开始时间',
            trigger: 'change'
          }],
          entryEndTime: [{
            required: true,
            validator: validateEntryEndTime,
            trigger: 'blur'
          }],
          entryPosition: [{
            required: true,
            type: 'string',
            message: '请选择入驻位置',
            trigger: 'change'
          }],
          projectType: [{
            required: true,
            type: 'string',
            message: '请选择项目类型',
            trigger: 'change'
          }],
          projectManager: [{
            required: true,
            type: 'string',
            message: '请填写项目经理',
            trigger: 'blur'
          }],
          managerTel: [{
              required: true,
              message: '请填写项目经理联系方式',
              trigger: 'blur'
            },
            {
              type: 'string',
              pattern: /^[1]+\d{10}$/,
              message: '请输入正确的联系方式',
              trigger: 'blur'
            }
          ],
          projectDoc: [{
            required: true,
            type: 'string',
            message: '请填写项目描述',
            trigger: 'blur'
          }],
        },

        fileUrl: this.CONFIG.file_url,
        // ifedit:false,   //是否可以修改编辑
        readonly: true, //是否只读
        labelWidth: 140,
        bealoonTrue: true,
        file: null,
        loadingStatus: false,
        fileUpLoadAction: "",
        name: "",
        //租户列表
        roleList: [],
        //项目名称
        projectList: [],
        //资源清单相关基础信息
        resourcesInfo: {
          severColumns: [{
              title: "*服务类型",
              align: "center",
              // width: 110,
              key: "severName",
              slot: "severName",
            },
            {
              title: "*操作系统",
              align: "center",
              width: 110,
              key: "id",
              slot: "os"
            },
            {
              title: "*raid方式",
              align: "center",
              children: [{
                  title: '*系统盘',
                  align: 'center',
                  width: 110,
                  slot: "sysRaid"
                },
                {
                  title: '*数据盘',
                  align: 'center',
                  width: 110,
                  slot: "dataRaid"
                },
              ]
            },
            {
              title: "*部署区域",
              align: "center",
              width: 110,
              slot: "place"
            },
            {
              title: "*台数",
              align: "center",
              width: 90,
              slot: "quantity"
            },
            {
              title: "测算依据/必要性说明",
              align: "center",
              // width: 140,
              slot: "purpose"
            },
            {
              slot: 'action',
              align: 'center',
              width: 90,
              renderHeader: (h, index) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'primary',
                      // size: 'small'
                    },
                    on: {
                      click: () => {
                        if (!this.ifedit) {
                          this.addRow()
                        }
                      }
                    }
                  }, '新增')
                ])
              }
            },
          ],

          transfer: true,
          // 资源服务title
          columns: [
            // {
            //   title: " ",
            //   align: "center",
            //   width: 60,
            //   key: "id",
            //   slot: "check",
            //   fixed: 'left'
            // },
            // {
            //     title: '服务类型',
            //     key: 'clazz',
            //     align: 'center',
            //     width: 100
            // },
            {
              title: '服务类型',
              key: 'serviceName',
              align: 'left',
              width: 150,
              fixed: 'left',
              slot: "serviceName"
            },
            {
              title: '服务名称    ',
              key: 'subName',
              align: 'left',
              minWidth: 160,
              slot: "subName"
            },
            {
              title: '*可选项',
              key: 'options',
              align: 'left',
              minWidth: 450,
              slot: 'options'
            },
            {
              title: '*测算依据',
              key: 'reason',
              align: 'left',
              minWidth: 300,
              slot: 'reason'
            },
          ],
        },
        //print 打印时的表头
        resourcesInfo2: {
          severColumns: [{
              title: "*服务类型",
              align: "center",
              // width: 110,
              key: "severName",
              slot: "severName",
            },
            {
              title: "*操作系统",
              align: "center",
              width: 110,
              key: "id",
              slot: "os"
            },
            {
              title: "*raid方式",
              align: "center",
              children: [{
                  title: '*系统盘',
                  align: 'center',
                  width: 110,
                  slot: "sysRaid"
                },
                {
                  title: '*数据盘',
                  align: 'center',
                  width: 110,
                  slot: "dataRaid"
                },
              ]
            },
            {
              title: "*部署区域",
              align: "center",
              width: 110,
              slot: "place"
            },
            {
              title: "*台数",
              align: "center",
              width: 90,
              slot: "quantity"
            },
            {
              title: "测算依据/必要性说明",
              align: "center",
              // width: 140,
              slot: "purpose"
            },
            {
              slot: 'action',
              align: 'center',
              width: 90,
              renderHeader: (h, index) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'primary',
                      // size: 'small'
                    },
                    on: {
                      click: () => {
                        if (!this.ifedit) {
                          this.addRow()
                        }
                      }
                    }
                  }, '新增')
                ])
              }
            },
          ],

          transfer: true,
          // 资源服务title
          columns: [{
              title: '服务类型',
              key: 'serviceName',
              align: 'left',
              width: 120,
              slot: "serviceName"
            },
            {
              title: '服务名称    ',
              key: 'subName',
              align: 'left',
              width: 120,
              slot: "subName"
            },
            {
              title: '*可选项',
              key: 'options',
              align: 'left',
              width: 300,
              slot: 'options'
            },
            {
              title: '*测算依据',
              key: 'reason',
              align: 'left',
              // minWidth: 300,
              slot: 'reason'
            },
          ],
        },
        //工具相关基础信息
        toolInfo: {
          toolColumns: [{
              title: '服务类型',
              key: 'clazz',
              align: 'left',
              width: 100,
              slot: "clazz"
            },
            {
              title: '服务类型',
              key: 'serviceName',
              align: 'left',
              width: 100,
              slot: "serviceName"
            },
            {
              title: '服务名称    ',
              key: 'subName',
              align: 'left',
              width: 100,
              slot: "subName"
            },
            {
              title: '*可选项',
              key: 'options',
              align: 'left',
              slot: 'options'
            },
            {
              title: '*测算依据',
              key: 'reason',
              align: 'left',
              slot: 'reason'
            }
            // {
            //     title: "单位",
            //     align: "center",
            //     minWidth: 80,
            //     key: "unit",
            // },
            // {
            //     title: "分配数量",
            //     align: "center",
            //     width: 100,
            //     key: "quantity",
            //     slot: "quantity"
            // },
            // {
            //     title: '单位',
            //     // key: 'unit',
            //     align: 'center',
            //     slot: 'unit'
            // },
          ],
          toolList: [],
          needResources: [],
          needSevers: [],
          toolColumns2: [{
              title: "可选服务器资源",
              align: "center",
              key: "name",
            },
            {
              title: '*数量',
              key: 'isUse',
              align: 'center',
              slot: 'count'
            },
            {
              title: '*单位',
              key: 'unit',
              align: 'center',
              slot: 'unit'
            },
            {
              title: '测算依据',
              key: 'reason',
              align: 'center',
              slot: 'reason'
            },
          ]
        },
        //数据相关基础信息
        dataInfo: {
          click: true,
          clickindex: "",
          columnsTitle: [
            "序号",
            "*字段名",
            "*字段类型",
            "*是否加密",
            "*是否必填",
            "备注"
          ],
        },
        accountInfo: {
          columns: [{
              title: "序号",
              align: "center",
              width: 80,
              key: "count",
              slot: "count",
            },
            {
              title: "*租户成员姓名",
              align: "center",
              width: 120,
              slot: "name"
            },
            {
              title: "*一级4A账号",
              align: "center",
              // width: 110,
              key: "fourA",
              slot: "fourA",
            },
            {
              title: "*成员归属",
              align: "center",
              // width: 110,
              key: "userCompany",
              slot: "userCompany",
            },
            {
              title: "*账号角色",
              align: "center",
              // width: 110,
              key: "userRole",
              slot: "userRole",
            },
            {
              title: "备注",
              align: "center",
              // width: 110,
              key: "des",
              slot: "des",
            },
            {
              slot: 'action',
              align: 'center',
              width: 90,
              renderHeader: (h, index) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'error',
                      size: 'small'
                    },
                    on: {
                      click: () => {
                        if (!this.ifedit) {
                          this.addAccountRow()
                        }
                      }
                    }
                  }, '新增')
                ])
              }
            },
          ]
        },
        accountIndex: [],
        applyinfo: {
          reqSubject: "",
          base: {
            applyDate: "",
            compId: "",
            userName: "",
            userId: "",
            applyCardId: "",
            telephone: "",
            email: "",
            applydept: ""
          },
          projectInfo: {
            roleId: "", //租户id
            roleName: "", //租户名称
            projectId: "", //关联项目ID
            projectName: "", //关联项目名称

            entryStartTime: "", //开始时间
            entryEndTime: "", //结束时间
            entryCycle: "", //入驻周期
            entryPosition: "", //入驻地址
            isContract: "", //是否签订合同
            projectType: "", //项目类型

            projectManager: "", //项目经理
            business: "",
            managerTel: "", //项目经理联系方式
            projectDoc: "" //项目介绍
          },
          remark: {
            alloType: "",
            entrySysId: "",
          },
          resourcesInfo: {
            len: 0, //合并的行数
            resourceChcekList: [], //选择的申请资源清单列表
            resourceInfo: [], //资源清单字段详情
            seversList: [], //云服务字段列表
          },
          resources: [],
          severs: [],
          tools: {
            checkList: [], //选择的列表
            checkResourceList: [], //选择的工具资源
            needResources: [],
            needSevers: []
          },
          datas: [],
          account: {
            peopleList: [],
            people: [
              // {
              //   peopleUserId: 0,
              //   peopleName: "",
              //   tenantName: "",
              //   fourA: "",
              //   igroup: "",
              //   outterCompany: "",
              //   isEtl: false,
              //   isPaas: false,
              //   isUap: false,
              //   isHadoop: false,
              //   isElse: false,
              //   hftps: [],
              //   paas: [],
              //   hadoops: [],
              //   elseAuthes: []
              // }
            ]
          },
          files: []
        },
        tempResource: [],
        tempTool: [], // 订购的工具资源
        printInfo: {
          applyinfo: {},

        },
        seversList: [], //物理机资源
        printBaseInfo: [],
        baseInfoLength: 0,
        printProject: [],
        projectInfoLength: 0,
        baseId: this.reqId + "base",
        projectInfoId: this.reqId + "project",
        temp_roleId: 0,
        apiServiceList: [],
        account: [],
        timer: null
      }
    },
    created: function() {
      // 已申请
      if (this.reqId != null) {
        this.getApplyInfo(); //获取表单详情
      } else if (this.draftsId != null) { // 草稿
        this.getDrafts()
      } else {
        this.getUserInfo(); // 获取登录用户信息
      }
    },
    mounted: function() {
      this.$nextTick(()=>{
        // this.setGuide()
      })
    },

    methods: {
      setGuide() {
        console.log("stepTitleId = ",this.stepTitleId)
        if(this.stepTitleId == 0){
          let data = [{
              element: '.step_3',
              intro: '步骤1：对应class为.step_1的元素进行选择提示。',
              position: 'right'
            },
            {
              element: '.step_4',
              intro: '步骤1：对应class为.step_1的元素进行选择提示。',
              position: 'right'
            },
            {
              element: '.step_5',
              intro: '步骤1：对应class为.step_1的元素进行选择提示。',
              position: 'right'
            },
            {
              element: '.step_6',
              intro: '步骤1：对应class为.step_1的元素进行选择提示。',
              position: 'right'
            }
          ]
          this.IntroJs().setOptions({
            prevLabel: "上一步",
            nextLabel: "下一步",
            skipLabel: "跳过",
            doneLabel: "完成",
            tooltipClass: 'customTooltip',
            steps: data
          }).oncomplete(() => {
            //点击结束按钮后执行的事件
          }).onbeforechange((targetElement ) =>{
            // this.stepTitleId = 1
            // this.$refs.stepInfo.chlickStep(5)
          }).onexit(() => {
            //点击跳过按钮后执行的事件
          }).start()
        }
      },
      // 导出资源数据
      exportResource() {
        var option = {
          title: ['', '工具名称', '资源类型', '服务名称', '细分项名', '可选项', '描述'],
          body: [],
          name: '入驻服务申请资源信息表_' + this.reqId,
          suffix: 'xlsx',
          merges: []
        }
        var resourceList = this.applyinfo.resourcesInfo.resourceInfo
        var toolList = this.toolInfo.toolList
        if (this.isEdit == 1) {
          resourceList = this.tempResource
          toolList = this.tempTool
        }
        console.log("toolList =", toolList)
        var row = 1
        var mergeRow = 1
        if (resourceList.length > 0) {
          option.body.push(['资源', '资源类型', '资源类型', '服务名称', '细分项名', '可选项', '描述'])
          option.merges.push({
            s: {
              r: 0,
              c: 1
            },
            e: {
              r: 0,
              c: 2
            }
          })
          resourceList.forEach(item => {
            if(item.check){
              var resource = this.sort(item.list, option, '')
              mergeRow += resource.length - 1

              option.merges.push({
                s: {
                  r: row,
                  c: 1
                },
                e: {
                  r: mergeRow,
                  c: 2
                }
              })
              mergeRow += 1
              row = mergeRow
            }
          })
          option.merges.push({
            s: {
              r: 0,
              c: 0
            },
            e: {
              r: mergeRow - 1,
              c: 0
            }
          })
        }
        if (toolList.length > 0) {
          if (option.body.length > 0) {
            mergeRow += 1
            row = mergeRow
          }
          option.body.push(['工具', '工具名称', '资源类型', '服务名称', '细分项名', '可选项', '描述'])
          const toolRow = row - 1
          toolList.forEach(tool => {
            tool.toolList.forEach(item =>{
              if(item.check){
                var resource = []
                if (item.needResources != undefined && item.needResources != null && item.needResources.length > 0) {
                  resource = this.sort(item.needResources, option, item.toolName)
                } else {
                  option.body.push(["", item.toolName, '无', '无', '无', '无', '无'])
                  resource = [1]
                }

                mergeRow += resource.length - 1

                option.merges.push({
                  s: {
                    r: row,
                    c: 1
                  },
                  e: {
                    r: mergeRow,
                    c: 1
                  }
                })

                mergeRow += 1
                row = mergeRow
              }
            })
          })

          option.merges.push({
            s: {
              r: toolRow,
              c: 0
            },
            e: {
              r: mergeRow - 1,
              c: 0
            }
          })
        }

        if (this.applyinfo.datas.length > 0) {
          var number = 0
          this.applyinfo.datas.forEach(item => {
            number += item.fields.length
          })
          option.body.push(['数据', '数据表总数(张)', "", '', '', '', this.applyinfo.datas.length])
          option.body.push(['数据', '数据字段总数(个)', "", '', '', '', number])

          row = mergeRow
          option.merges.push({
            s: {
              r: row,
              c: 0
            },
            e: {
              r: mergeRow + 1,
              c: 0
            }
          }, {
            s: {
              r: row,
              c: 1
            },
            e: {
              r: row,
              c: 5
            }
          }, {
            s: {
              r: row + 1,
              c: 1
            },
            e: {
              r: row + 1,
              c: 5
            }
          })
        }



        if (option.body.length > 0) {
          excel.exportFromArray(option)
        } else {
          this.$Message.error("暂无资源可导出!")
        }
      },
      sort(data, option, toolName) {
        var t = JSON.stringify(data)
        var temp = JSON.parse(t)
        var temp2 = []
        temp2 = temp.sort((a, b) => {
          return a['clazz'].localeCompare(b['clazz']) //用本地特定的顺序来比较两个字符串。
        })
        var resource = []
        temp2.forEach(item => {
          item.clazz = item.clazz.split(".").length > 1 ? item.clazz.split(".")[1] : item.clazz
          item.serviceName = item.serviceName.split(".").length > 1 ? item.serviceName.split(".")[1] : item
            .serviceName
          item.subName = item.subName.split(".").length > 1 ? item.subName.split(".")[1] : item.subName
          var otherInfo = ""
          if (item.resourcetype == 0) {
            otherInfo = "数量：" + item.val + "  单位：" + item.quotaUnit
          } else if (item.resourcetype == 1) {
            otherInfo = item.val
          } else if (item.resourcetype == 3) {
            otherInfo = item.options[0] + ': ' + item.val
          } else if (item.resourcetype == 4) {
            otherInfo = item.val
          } else if (item.resourcetype == 5) {
            otherInfo = "双副本数量：" + item.val + "  单位：" + item.quotaUnit + "  单副本数量：" + item.val / 2
          } else if (item.resourcetype == 6) {
            otherInfo = "三副本数量：" + item.val + "  单位：" + item.quotaUnit + "  单副本数量：" + parseFloat(item.val / 3)
              .toFixed(
                2)
          }
          var temp = []
          temp.push("")
          if (toolName == "") {
            temp.push(item.clazz)
          } else {
            temp.push(toolName)
          }
          temp.push(item.clazz)
          temp.push(item.serviceName)
          temp.push(item.subName)
          temp.push(otherInfo)
          temp.push(item.purpose)
          option.body.push(temp)
          resource.push(temp)
        })
        return resource
      },
      exportData() {
        if (this.applyinfo.datas != undefined && this.applyinfo.datas != null) {
          if (this.applyinfo.datas.length > 0) {
            var option = [];
            this.toolInfo.toolList.forEach(item => {
              item.toolList.forEach(tool => {
                if (tool.check && tool.spServiceType == "dataEtl") {
                  option.push(this.exportDataEtl(tool));
                }
              })
            })
            this.applyinfo.datas.forEach(item => {
              if (item.serviceId != undefined && item.serviceId != null && item.serviceId > 0) {
                option.push(this.exportExistData(item));
              } else {
                option.push(this.exportCustomData(item));
              }
            })
            // 处理sheet名
            var tempSheetName = []
            for (let i = 0; i < option.length; i++) {
              if (tempSheetName.find(e => e == option[i].sheetName) != undefined) {
                option[i].sheetName += i
              } else {
                tempSheetName.push(option[i].sheetName)
              }
            }

            excel.exportSheetFromArray(option)
          } else {
            this.$Message.error("暂无数据目录信息可导出!")
          }
        } else {
          this.$Message.error("暂无数据目录信息可导出!")
        }
      },
      /**
       * 获取数据需求信息
       * @param {Object} data
       */
      exportDataEtl(data) {
        var option = {
          title: [],
          body: [],
          name: '入驻服务申请数据目录信息表_' + this.reqId,
          suffix: 'xlsx',
          sheetName: '数据需求信息',
        }
        var table = data;
        option.body.push(["租户名称", "项目名称", "租户位置", "运营组接口人员", "数据需求频率", "数据生效日期", "安全流程是否走完", "安全加密要求", "抽样要求", "ETL工具",
          "采集数据目录", "数据需求描述", "备注"
        ]);
        option.body.push([this.applyinfo.projectInfo.roleName, this.applyinfo.projectInfo.projectName, this.applyinfo
          .remark.entrySysName,
          this.applyinfo.projectInfo.business, data.spContent.dataFrequent, data.spContent.actTime, data.spContent
          .isSafe, data.spContent.encryption,
          data.spContent.extDemand, data.spContent.etlTool, data.spContent.etlPath, data.spContent.reqDes, data
          .spContent.remark
        ]);

        return option;
      },
      exportExistData(data) {
        var option = {
          title: [],
          body: [],
          name: '入驻服务申请数据目录信息表_' + this.reqId,
          suffix: 'xlsx',
          sheetName: '',
          merges: [{
              s: {
                r: 0,
                c: 0
              },
              e: {
                r: 0,
                c: 13
              }
            },
            {
              s: {
                r: 4,
                c: 0
              },
              e: {
                r: 4,
                c: 13
              }
            }
          ]
        }
        var table = data.service;
        var fields = data.fields;
        var temp = table["tableName"].length > 20 ? table["tableName"].substring(0, 20) + '...' : table["tableName"]
        var badchars = "][*?\/\\".split("");
        badchars.forEach(function(c) {
          if (temp.indexOf(c) != -1)
            temp = temp.replace(c, '');
        });
        option.sheetName = temp;

        var body = [];
        body.push(1);
        body.push(table["tableName"]);
        body.push(table["tableNameEn"]);
        body.push(table["dataLevel"]);
        body.push(table["domain"]);
        body.push(table["subjectField"]);
        body.push(table["dataOpenLevel"]);
        body.push(table["cycleType"]);
        body.push(table["keepTime"]);
        body.push(table["keepUnit"]);
        body.push(table["dataScope"]);
        body.push(table["oriSys"]);
        body.push(table["caliber"]);
        body.push(data.purpose);
        body.push(data["fields"].length + '/' + data['len']);

        var tableTitle = [];
        tableTitle.push("（" + table["tableName"] + "）" + "数据表信息");
        option.body.push(tableTitle);
        option.body.push(['序号', '表中文名', '表英文名', '层级', '所属域', '主题域', '数据开放推荐级别', '更新周期', '保存时长', '保存时长单位', '数据范围',
          '所属系统',
          '业务口径', '用途', '字段数占比'
        ]);
        option.body.push(body);

        option.body.push(["", "", "", "", "", "", "", "", "", "", "", ""]);

        option.body.push(["选择字段信息"]);
        option.body.push(["序号", "字段属性", "字段名称", "数据类型", "数据样例", "是否加密", "是否必选", "字段必要性说明"]);
        for (var i = 0; i < fields.length; i++) {
          var arr = [];
          arr.push(i + 1);
          arr.push(fields[i].fieldNameEn);
          arr.push(fields[i].fieldName);
          arr.push(fields[i].fieldType);
          arr.push(fields[i].fieldEnum);
          if (fields[i].isEncryption == 1) {
            arr.push("是");
          } else {
            arr.push("否");
          }
          if (fields[i].isRequired == 1) {
            arr.push("是");
          } else {
            arr.push("否");
          }
          arr.push(fields[i].remark);

          option.body.push(arr);
        }

        return option;
      },
      exportCustomData(data) {
        var option = {
          title: [],
          body: [],
          name: '入驻服务申请数据目录信息表_' + this.reqId,
          suffix: 'xlsx',
          sheetName: '',
          merges: [{
              s: {
                r: 0,
                c: 0
              },
              e: {
                r: 0,
                c: 3
              }
            },
            {
              s: {
                r: 4,
                c: 0
              },
              e: {
                r: 4,
                c: 5
              }
            }
          ]
        }

        var table = data;
        var fields = data.fields;
        var temp = table["tableName"] + "（自定义数据表）"
        var temp2 = temp.length > 20 ? temp.substring(0, 20) + '...' : temp;
        var badchars = "][*?\/\\".split("");
        badchars.forEach(function(c) {
          if (temp2.indexOf(c) != -1)
            temp2 = temp2.replace(c, '');
        });
        option.sheetName = temp2

        var body = [];
        body.push(1);
        body.push(table["tableName"]);
        body.push(table["purpose"]);
        body.push(table["cycleType"]);
        body.push(table["domain"]);

        var tableTitle = [];
        tableTitle.push("（" + table["tableName"] + "）" + "自定义数据表信息");
        option.body.push(tableTitle);
        option.body.push(['序号', '表名', '用途', '表类型', '所属域']);
        option.body.push(body);

        option.body.push(["", "", "", ""]);

        option.body.push(["自定义字段信息"]);
        option.body.push(["序号", "字段名称", "字段类型", "是否加密", "是否必选", "字段必要性说明"]);
        for (var i = 0; i < fields.length; i++) {
          var arr = [];
          arr.push(i + 1);
          arr.push(fields[i].fieldName);
          arr.push(fields[i].fieldType);
          if (fields[i].isEncryption == 1) {
            arr.push("是");
          } else {
            arr.push("否");
          }
          if (fields[i].isRequired == 1) {
            arr.push("是");
          } else {
            arr.push("否");
          }
          arr.push(fields[i].remark);

          option.body.push(arr);
        }

        return option;
      },
      exportAccount() {
        console.log("----导出账号信息----", this.applyinfo.account.people);
        if (this.applyinfo.account != undefined && this.applyinfo.account != null) {
          if (this.applyinfo.account.people != undefined && this.applyinfo.account.people != null) {
            var people = this.applyinfo.account.people;
            if (people.length > 0) {
              var option = {
                title: [],
                body: [],
                name: '入驻服务申请账号信息表_' + this.reqId,
                suffix: 'xlsx',
                sheetName: '',
                merges: []
              }

              var title = ["姓名", "已有的一级4A主账号", "账号类型", "账号属性", "ip信息"]
              option.body.push(title);

              people.forEach(item => {
                if (item.isSever) {
                  item.severs.forEach(value => {
                    var account = [];
                    account.push(item.peopleName);
                    account.push(item.fourA);
                    account.push("主机账号");
                    account.push(value.accountAttr);
                    account.push(value.ip);

                    option.body.push(account);
                  })
                }

                if (item.isDb) {
                  item.dbs.forEach(value => {
                    var account = [];
                    account.push(item.peopleName);
                    account.push(item.fourA);
                    account.push("数据库账号");
                    account.push(value.accountAttr);
                    account.push(value.ip);

                    option.body.push(account);
                  })
                }

                // if(item.isHadoop){
                //   item.hadoops.forEach(value=>{
                //     var account = [];
                //     account.push(item.peopleName);
                //     account.push(item.fourA);
                //     account.push("Hadoop账号");

                //     option.body.push(account);
                //   })
                // }

                // if(item.isHftp){
                //   item.hftps.forEach(value=>{
                //     var account = [];
                //     account.push(item.peopleName);
                //     account.push(item.fourA);
                //     account.push("UAP账号");

                //     option.body.push(account);
                //   })
                // }

                // if(item.isPaas){
                //   item.paas.forEach(value=>{
                //     var account = [];
                //     account.push(item.peopleName);
                //     account.push(item.fourA);
                //     account.push("PaaS账号");

                //     option.body.push(account);
                //   })
                // }

                // if(item.isDacp){
                //   item.dacps.forEach(value=>{
                //     var account = [];
                //     account.push(item.peopleName);
                //     account.push(item.fourA);
                //     account.push("dacps账号");

                //     option.body.push(account);
                //   })
                // }

                // if(item.isElse){
                //   item.elseAuthes.forEach(value=>{
                //     var account = [];
                //     account.push(item.peopleName);
                //     account.push(item.fourA);
                //     account.push("其他账号");

                //     option.body.push(account);
                //   })
                // }
              })

              excel.exportFromArray(option)
            } else {
              this.$Message.error("暂无账号信息可导出!")
            }
          } else {
            this.$Message.error("暂无账号信息可导出!")
          }
        } else {
          this.$Message.error("暂无账号信息可导出!")
        }
      },
      // 打印
      print() {
        console.log("打印------->")
        var temp = []
        temp.push({
          title: "提单人信息",
          type: "dafault",
          info: {
            printObject: this.printBaseInfo,
            printLength: this.baseInfoLength
          }
        })
        temp.push({
          title: "入驻项目信息",
          type: "dafault",
          info: {
            printObject: this.printProject,
            printLength: this.projectInfoLength
          }
        })
        temp.push({
          title: "使用人信息",
          type: "usePeople",
          info: {
            applyinfo: this.applyinfo.account.people
          }
        })
        this.printInfo.applyinfo.resourcesInfo.resourceInfo.forEach(item => {
          this.printInfo.applyinfo.resourcesInfo.resourceChcekList.push(item.resourceName)
        })
        temp.push({
          title: "资源信息",
          type: "entry_resoureceInfo",
          info: {
            resourcesInfo2: this.resourcesInfo2,
            applyinfo: this.printInfo.applyinfo
          }
        })
        var toolTemp = JSON.parse(JSON.stringify(this.toolInfo))
        var toolTemp2 = []
        var openApiPlatformList = []
        toolTemp.toolList.forEach(item => {
          item.toolList.forEach(t => {
            if (t.spServiceType == "openApiPlatform" && t.spContent) {
              openApiPlatformList = t.spContent.datas
            }
            this.$set(t, "check", true)
            toolTemp2.push(t)
          })
        })
        this.$set(toolTemp, "toolList", toolTemp2)
        temp.push({
          title: "工具信息",
          type: "entry_toolInfo",
          info: {
            toolInfo: toolTemp,
            applyinfo: this.printInfo.applyinfo
          }
        })
        temp.push({
          title: "物理机",
          type: "entry_server",
          info: {
            server: this.seversList,
            applyinfo: this.printInfo.applyinfo
          }
        })
        temp.push({
          title: "数据信息",
          type: "entry_dataInfo",
          info: {
            openApiPlatformList: openApiPlatformList,
            applyinfo: this.printInfo.applyinfo
          }
        })
        if (this.serviceType == "entry") {
          temp.push({
            title: "账号信息",
            type: "entry_account",
            info: {
              applyinfo: this.printInfo.applyinfo
            }
          })
        } else if (this.serviceType = "entry_v2") {
          temp.push({
            title: "账号信息",
            type: "entry_account",
            info: {
              applyinfo: this.setExpand()
            }
          })
        }
        // this.printInfo.toolInfo = this.toolInfo
        // this.printInfo.printBaseInfo = this.printBaseInfo
        // this.printInfo.baseInfoLength = this.baseInfoLength
        // this.printInfo.printProject = this.printProject
        // this.printInfo.projectInfoLength = this.projectInfoLength
        // this.printInfo.resourcesInfo2 = this.resourcesInfo2

        const {
          href
        } = this.$router.resolve({
          path: '/other_page/print',
          query: {
            serviceType: this.serviceType,
            printName: "入驻申请表单",
            printId: this.reqId
          }
        })
        sessionStorage[this.reqId] = JSON.stringify(temp)
        window.open(href, '_blank')
        this.newValue = false
      },
      cancel() {
        this.newValue = false
      },
      setExpand() {
        var temp = JSON.stringify(this.$refs.account.account);
        console.log("---temp--",temp);
        var account = JSON.parse(temp);
        account.forEach(item => {
          item.isExpand = 0;
        })
        return account;
      },
      /**
       * 切换步骤
       * @param {Object} stepId
       */
      setApplInfo(stepId) {
        var isSubmit = true
        if (stepId == 0) {
          this.applyinfo.projectInfo = this.$refs.projectInfo.applyinfo.projectInfo
          this.projectList = this.$refs.projectInfo.projectList
          if (!this.applyinfo.remark.entrySysId) {
            this.$Message.info('请先勾线入驻资源池！');
            isSubmit = false
          }
          // isSubmit = this.$refs.projectInfo.validate()
        } else if (stepId == 1) {
          this.applyinfo.resourcesInfo = this.$refs.resoureceInfo.applyinfo.resourcesInfo
          this.applyinfo.resources = this.$refs.resoureceInfo.applyinfo.resources
          // isSubmit = !this.$refs.resoureceInfo.validate()
        } else if (stepId == 2) {
          // this.$refs.toolInfo.updateToolList()
          // this.applyinfo.tools = this.$refs.toolInfo.applyinfo.tools
          if (this.toolInfo && !this.ifedit) {
            var indes = []
            this.seversList.forEach((items, idnexs) => {
              if (!items.forToolServiceIds || items.forToolServiceIds.length == 0) {
                indes.push(items)
              }
            })
            this.seversList = indes

            this.toolInfo.toolList.some(item => {
              item.toolList.some(tool => {
                if (tool.needSevers && tool.needSevers.length > 0 && tool.packageLists) {
                  if (tool.check) {
                    tool.packageLists.forEach(packages => {
                      if (packages.modelName == tool.defaultResourcesModel) {
                        packages.package.severs.forEach(sever => {
                          this.seversList.push(JSON.parse(JSON.stringify(sever)))
                        })
                      }
                    })
                  }
                }
              })
            })
            this.$forceUpdate()
          }
          isSubmit = true
        } else if (stepId == 3) {
          // this.applyinfo.datas = this.$refs.dataInfo.applyinfo.datas
          // isSubmit = !this.$refs.dataInfo.validate()
        } else if (stepId == 4) {
          // this.applyinfo.account.people = this.$refs.projectInfo.applyinfo.account.people
          // isSubmit = !this.$refs.account.validate()
        } else if (stepId == 5) {
          isSubmit = true
        } else {
          isSubmit = true
        }
        if (!this.ifedit) {
          if(this.applyinfo.account.people != null && this.applyinfo.account.people.length>0){
            this.getPeopleAccount();
          }else{
            this.account = [];
          }
        }
        console.log("---this.account--",this.account);
        // this.setOverviewAccount();
        return isSubmit
      },

      //获取租户角色
      getRoleLis(userId) {
        var url = this.CONFIG.url_know + "/getManager/" + userId
        var that = this;
        ajax.get({
          url: url,
          that: that,
          params: null,
          success: function(data) {
            that.roleList = data

            if (that.temp_roleId > 0) {
              that.checkRole(that.temp_roleId);
            }
          }
        })
      },
      /**
       * 获取草稿详情
       */
      getDrafts() {
        var url = this.CONFIG.base_url_test + "/draft/content/" + this.draftsId
        var that = this;
        ajax.get({
          url: url,
          that: that,
          params: null,
          success: function(data) {
            that.temp_roleId = data.req.base.roleId
            that.applyinfo.remark = data.req.object.remark
            that.applyinfo.base = data.req.object.base
            that.seversList = data.req.object.severs
            that.getRoleLis(data.req.object.base.userId)
            that.applyinfo.files = data.req.files
            that.applyinfo.projectInfo = data.req.object.projectInfo
            that.applyinfo.reqSubject = data.req.puslicInfo.reqSubject
            that.getResourceList(data.req.object);
          }
        })
      },
      checkRole(roleId) {
        if (roleId != undefined && roleId != null && roleId != "") {
          this.roleList.some(item => {
            if (roleId == item.id) {
              this.projectList = item.projects
              return true
            }
          })
        }
      },

      // 获取提交表单人基本信息
      getApplyUser(userId) {
        var that = this;
        var url = this.CONFIG.url_know + '/user/' + userId;
        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            that.applyinfo.base.userName = data.user_name
            that.applyinfo.base.userId = data.id
            that.applyinfo.base.applyCardId = data.id_card
            that.applyinfo.base.telephone = data.phone
            that.applyinfo.base.email = data.email
            that.applyinfo.base.applydept = that.processInfo.dptName
          }
        })
      },
      /**
       * 获取申请表单信息
       */
      getApplyInfo() {
        var data = JSON.parse(JSON.stringify(this.processInfo))
        this.dataInfoEdit = this.isEdit
        if (this.processInfo.content.remark != undefined) {
          this.applyinfo.remark = this.processInfo.content.remark
        }
        // this.getApplyUser(data.base.userId)
        this.setUserInfo(data.base.userFBean)
        this.applyinfo.base.applydept = this.processInfo.dptName
        this.applyinfo.reqSubject = this.processInfo.reqSubject
        this.setProjectInfo(data.base.project)
        this.applyinfo.account = this.setAccount(data.content.account);
        // 判断是否可以编辑 isEdit= 1可以编辑
        this.seversList = data.content.severs
        if (this.isEdit == 23 || this.isEdit == 1) {
          this.temp_roleId = this.processInfo.base.role.id
          this.getRoleLis(data.base.userFBean.id);
          this.checkRole(this.processInfo.base.role.id)
          this.getResourceList(data.content)
        } else {
          this.handleApplyInfo(data)
          this.lodingOver = false
        }
        if (data.files != undefined && data.files != null) {
          this.applyinfo.files = data.files
        }
        this.printInfo.applyinfo = JSON.parse(JSON.stringify(this.applyinfo))
        if (this.ifedit) {
          this.stepTitleId = 6
        }
        console.log("---getaap-------");
        this.$forceUpdate()

      },
      setUserInfo(userInfo) {
        this.applyinfo.base.userName = userInfo.user_name
        this.applyinfo.base.userId = userInfo.id
        this.applyinfo.base.applyCardId = userInfo.id_card
        this.applyinfo.base.telephone = userInfo.phone
        this.applyinfo.base.email = userInfo.email
      },
      setAccount(account) {
        if (account != null && account.people != undefined && account.people != null) {
          account.peopleList = [];
          for (var i = 0; i < account.people.length; i++) {
            if (account.people[i].servers != undefined && account.people[i].servers.length > 0) {
              account.people[i].isSever = true;
            }

            if (account.people[i].severs != undefined && account.people[i].severs.length > 0) {
              account.people[i].isSever = true;
            }

            if (account.people[i].dbs.length > 0) {
              account.people[i].isDb = true;
            }

            if (account.people[i].hadoops.length > 0) {
              account.people[i].isHadoop = true;
            }

            if (account.people[i].hftps.length > 0) {
              account.people[i].isHftp = true;
            }

            if (account.people[i].paas.length > 0) {
              account.people[i].isPaas = true;
            }

            if (account.people[i].dacps.length > 0) {
              account.people[i].isDacp = true;
            }

            if (account.people[i].elseAuthes.length > 0) {
              account.people[i].isElse = true;
            }

            var j = {
              id: "",
              user_name: "",
              fourA: "",
              structs: []
            }
            var item = account.people[i]
            if (item.peopleUserId != undefined && item.peopleUserId != null &&
              typeof item.peopleUserId == 'number' && item.peopleUserId != 0) {
              j.id = account.people[i].peopleUserId;
            } else {
              account.people[i].peopleUserId = account.people[i].peopleName;
              j.id = account.people[i].peopleName;
            }
            j.fourA = item.fourA
            j.user_name = account.people[i].peopleName;
            account.peopleList.push(j);

            if (account.people[i].isExpand == undefined) {
              account.people[i].isExpand = -1;
            }
          }
        } else {
          account = {
            people: [],
            peopleList: []
          }
        }
        return account;
      },
      // setOverviewAccount(){
      //   console.log("---setOverviewAccount-----",this.account);
      //   this.$refs.overview.getAccount(this.account);
      // },
      /**
       * 申请资源详情-可编辑-转换info格式
       * data为表单中的数据，result为所有资源数据
       * @param {Object} content
       */
      handleInfo(data, result) {
        var info = this.applyinfo
        if (data.datas == undefined || data.datas == null) {
          info.datas = []
        } else {
          info.datas = data.datas
        }
        // this.tempTool = []; // 存放订购的工具
        data.tools.forEach((tool, index) => {
          var t = result.toolList.findIndex(e => tool.toolId == e.id)
          if (!tool.reqId) {
            tool.reqId = JSON.parse(JSON.stringify(tool.id))
          }
          // 判断该工具是否存在，
          tool.id = tool.toolId
          tool.check = true
          // 现有工具无表单中的数据
          if (t == -1) {
            result.toolList.push(tool)
          } else {
            var toolTemp = JSON.parse(JSON.stringify(result.toolList[t]))
            if (tool.needResources) {
              tool.needResources.forEach((i, index) => {
                var ttempIndex = toolTemp.needResources.findIndex(e => e.id == i.serviceId && e.modelName ==
                  tool.resourcesPackage)
                if (ttempIndex != -1) {
                  if (result.toolList[t].needResources[ttempIndex].quotaValue != i.val) {
                    tool.customResources = true
                  }
                  result.toolList[t].needResources[ttempIndex].val = i.val
                  result.toolList[t].needResources[ttempIndex].unit = i.unit
                  // result.toolList[t].needResources[ttempIndex].quotaValue = i.val
                  // result.toolList[t].needResources[ttempIndex].quotaUnit = i.unit
                  result.toolList[t].needResources[ttempIndex].purpose = i.purpose
                }
              })
            }

            if (tool.resourcesPackage) {
              result.toolList[t].defaultResourcesModel = tool.resourcesPackage
            }
            result.toolList[t].default = tool.customResources
            if(tool.needSevers){
              tool.needSevers.forEach(se =>{
                if(!se.modelName){
                  se.modelName = tool.resourcesPackage
                }
              })
              result.toolList[t].needSevers = tool.needSevers
            }
            result.toolList[t].spContent = tool.spContent
            result.toolList[t].reqId = tool.reqId
            result.toolList[t].check = true
            result.toolList[t].id = tool.toolId
          }
        });
        data.resources.forEach(res => {
          var t = result.resourceList.findIndex(e => e.id == res.serviceId)
          res.check = true
          if (t != -1) {
            result.resourceList[t] = res
          } else {
            result.resourceList.push(res)
          }
        });

        info.account = this.setAccount(data.account);
      },
      /**
       * 申请表单详情-不可编辑——处理表单详情
       * @param {Object} data
       */
      handleApplyInfo(data) {
        var info = this.applyinfo
        var content = data.content
        var projectModel = data.projectModel
        if (content.datas == undefined || content.datas == null) {
          info.datas = []
        } else {
          info.datas = content.datas
        }
        content.tools.forEach((tool, index) => {
          if (tool.id) {
            if (!tool.reqId) {
              tool.reqId = tool.id
            }
            tool.id = tool.toolId
          }
          if (!tool.defaultResourcesModel && tool.resourcesPackage) {
            tool.defaultResourcesModel = tool.resourcesPackage
            tool.default = tool.customResources
          }
          if (tool.needResources) {
            tool.needResources.forEach(item => {
              item.modelName = tool.defaultResourcesModel
              item.quotaValue = item.val
              item.quotaUnit = item.unit
            })
          }
          if(tool.needSevers){
            tool.needSevers.forEach(item => {
              item.modelName = tool.defaultResourcesModel
            })
          }
          content.tools[index].check = true
        });
        content.resources.forEach((tool, index) => {
          content.resources[index].check = true
        });

        this.applyinfo.resourcesInfo.resourceInfo = []
        this.handleSpan(content.resources)
        this.setToolList(content.tools)

      },
      //设置项目基础详情
      setProjectInfo(data) {
        var info = this.applyinfo.projectInfo
        info.roleId = this.processInfo.base.role.id
        info.roleName = this.processInfo.base.role.tenant_name
        info.projectId = data.id
        info.projectName = data.project
        info.entryStartTime = data.create_time != null && data.create_time != '' ? this.formatTime(data.create_time) :
          ''
        info.entryEndTime = data.end_time != null && data.end_time != '' ? this.formatTime(data.end_time) : ''
        info.entryCycle = data.cycle
        info.entryPosition = data.position
        info.isContract = data.isContract
        info.projectType = data.projectType
        info.projectManager = data.manager
        if (data.business == undefined || data.business == null || data.business == "") {
          info.business = data.tenant_business
        } else {
          info.business = data.business
        }
        info.managerTel = data.manager_phone
        info.projectDoc = data.des
      },
      /**
       * 资源清单_获取基础信息
       */
      getResourceList(content) {
        this.lodingOver = true
        var url = this.CONFIG.progress_url + "/service-list/by-pool/" + this.applyinfo.remark.entrySysId
        var that = this;
        ajax.get({
          url: url,
          that: that,
          params: null,
          success: function(data) {
            console.log("----55555---",data);
            that.allServerList = data.severList
            // 如果是草稿或者申请表单，处理表单数据与之基础目录匹配赋值
            if (content) {
              that.handleInfo(content, data)
            }

            that.handleSpan(data.resourceList); // 合并资源
            that.setToolList(data.toolList); //合并工具
            clearTimeout(that.timer); //清除延迟执行
            that.timer = setTimeout(()=>{ //设置延迟执行
              that.lodingOver = false
            },1000);
            // that.setInfo()
          }
        })
      },
      /**
       * 处理工具集合
       */
      setToolList(toolList) {
        var temp = []
        var openApiPlatformIndex = -1
        var dataEtlIndex = -1
        toolList.forEach((item, index) => {
          if (item.check) {
            if (item.spServiceType === "openApiPlatform") {
              openApiPlatformIndex = index
            } else if (item.spServiceType == 'dataEtl') {
              dataEtlIndex = index
            }
          }
        })
        var status = false
        if (openApiPlatformIndex != -1) {
          this.getDetail(toolList[openApiPlatformIndex], 'openApiPlatform')
        }
        if (dataEtlIndex != -1) {
          this.getDetail(toolList[dataEtlIndex], 'dataEtl')
        }
        toolList.forEach((item, index) => {
          toolList[index].apiServ = []
          toolList[index].toolId = item.id
          if (!item.check) {
            toolList[index].check = false //设置默认为未选择
          }
          if (!item.default) {
            toolList[index].default = false //设置是否为默认套餐
          }
          item.resourcesPackage = item.defaultResourcesModel
          item.customResources = item.default

          if (item.needResources != null) {
            var resourceTemp = []
            item.needResources.forEach((i, k) => {
              if (!toolList[index].needResources[k].serviceId) {
                toolList[index].needResources[k].serviceId = i.id
              }
              if (item.check) {
                var t = i.val
                if (i.quotaValue) {
                  if (i.resourcetype == 4) {
                    item.needResources[k].quotaValue = JSON.parse(i.quotaValue)
                  } else if (i.resourcetype == 0 || i.resourcetype == 5 || i.resourcetype == 6) {
                    item.needResources[k].quotaValue = parseFloat(i.quotaValue)
                  }
                }
                if (t) {
                  if (i.resourcetype == 4) {
                    item.needResources[k].val = JSON.parse(t)
                  } else if (i.resourcetype == 0 || i.resourcetype == 5 || i.resourcetype == 6) {
                    item.needResources[k].val = parseFloat(t)
                  }
                } else {
                  item.needResources[k].val = i.quotaValue
                  item.needResources[k].unit = i.quotaUnit
                }
                item.needResources[k].purpose = i.purpose
                item.needResources[k].check = true

                toolList[index].needResources[i] = item.needResources[k]
              } else {
                // 处理默认资源信息
                var t = i.quotaValue
                if (i.resourcetype == 4 && (typeof i.quotaValue == 'string')) {
                  i.quotaValue = JSON.parse(t)
                  i.val = JSON.parse(t)
                } else if (i.resourcetype == 0 || i.resourcetype == 5 || i.resourcetype == 6) {
                  i.quotaValue = parseFloat(t)
                  i.val = parseFloat(t)
                } else {
                  i.val = t
                }
                toolList[index].needResources[k].check = true
                toolList[index].needResources[k].toolId = item.id
                toolList[index].needResources[k].unit = toolList[index].needResources[k].quotaUnit
                toolList[index].needResources[k].quantity = toolList[index].needResources[k].quota
                toolList[index].needResources[k].serviceId = i.id
                if (!toolList[index].needResources[k].purpose) {
                  toolList[index].needResources[k].purpose = "默认"
                }
              }
              if (!i.purpose) {
                i.purpose = "默认"
              }
            })
            // 对工具分套餐
            if (item.spServiceType != 'dataEtl') {
              this.handlePackageInfo(item)
            }
          }
          // if(!item.needResources && item.needResources .length == 0 && item.needSevers){
          //   // 对工具分套餐
          //   if (item.spServiceType != 'dataEtl') {
          //     this.handlePackageInfo(item)
          //   }
          // }

          // 分组
          if (temp.find(e => e.clazz == item.clazz)) {
            temp.find(e => e.clazz == item.clazz).toolList.push(toolList[index])
          } else {
            temp.push({
              clazz: item.clazz,
              toolList: [toolList[index]]
            })
          }
        })

        this.toolInfo.toolList = temp
        this.toolKey = new Date().getTime()
      },
      /**
       * 处理工具套餐
       * @param {Object} row
       */
      handlePackageInfo(row) {
        // 对资源套餐分组
        var packageLists = []
        if (row.needResources) {
          row.needResources.forEach(item => {
            var t1 = packageLists.find(e => e.modelName == item.modelName)
            if (t1) {
              if (row.defaultResourcesModel == item.modelName) {
                t1.defaultResourcesModel = true
              }
              t1.package.toolServiceList.push(item)
            } else {
              packageLists.push({
                package: { //工具关联的资源
                  toolServiceList: [item],
                  severs: []
                },
                modelName: item.modelName,
                defaultResourcesModel: row.defaultResourcesModel == item.modelName ? true : false,
              })
            }
          })
        }
        if (row.needSevers) {
          console.log("合并--套餐 ", row.needSevers)
          row.needSevers.forEach(item => {
            if(!item.forTool){
              this.$set(item, "forTool", row.toolName)
              this.$set(item, "forToolServiceIds", [row.id])
            }
            var t1 = packageLists.find(e => e.modelName == item.modelName)
            if (t1) {
              if (row.defaultResourcesModel == item.modelName) {
                t1.defaultResourcesModel = true
              }
              t1.package.severs.push(item)
            } else {
              packageLists.push({
                package: { //工具关联的资源
                  toolServiceList: [],
                  severs: [item]
                },
                modelName: item.modelName,
                defaultResourcesModel: row.defaultResourcesModel == item.modelName ? true : false,
              })
            }
          })
        }
        console.log("packageLists = ", packageLists)
        this.$set(row, "packageLists", packageLists)
      },

      async getDetail(item, type) {
        if (!item.spContent) {
          var param = {
            spServiceType: item.spServiceType,
            alloId: item.reqId
          }
          var that = this
          await this.myAjax.get({
            url: this.CONFIG.progress_url + "/sp-list/detail",
            that: that,
            params: param,
            success: function(data) {
              if (type == 'openApiPlatform') {
                if (data.hasAccount) {
                  data.hasAccount = 1
                } else {
                  data.hasAccount = 0
                }
              }
              if (type == 'dataEtl') {
                data.actTime = that.formatTime(data.actTime)
                if (data.ifNeedPublicData == 1) {
                  data.ifNeedPublicData = true
                } else {
                  data.ifNeedPublicData = false
                }
                if (data.ifNeedPrivateData == 1) {
                  data.ifNeedPrivateData = true
                } else {
                  data.ifNeedPrivateData = false
                }
                data.privateTransmisMode = JSON.parse(data.privateTransmisMode)
                data.publicTransmisMode = JSON.parse(data.publicTransmisMode)
              }
              that.$set(item, "spContent", data)
              that.toolKey = new Date().getTime()
            },
          })
        } else {
          var data = item.spContent
          if (type == 'openApiPlatform') {
            if (data.hasAccount) {
              data.hasAccount = 1
            } else {
              data.hasAccount = 0
            }
          }
          if (type == 'dataEtl') {
            data.actTime = this.formatTime(data.actTime)
            if (data.ifNeedPublicData == 1) {
              data.ifNeedPublicData = true
            } else {
              data.ifNeedPublicData = false
            }
            if (data.ifNeedPrivateData == 1) {
              data.ifNeedPrivateData = true
            } else {
              data.ifNeedPrivateData = false
            }
            data.privateTransmisMode = JSON.parse(data.privateTransmisMode)
            data.publicTransmisMode = JSON.parse(data.publicTransmisMode)
          }
        }
      },
      /**
       * 设置提单用户基本信息
       */
      getUserInfo() {
        var temp = this.$store.state.user
        this.applyinfo.base.userName = temp.user_name
        this.applyinfo.base.userId = temp.id
        this.applyinfo.base.applyCardId = temp.id_card
        this.applyinfo.base.telephone = temp.phone
        this.applyinfo.base.email = temp.email
        this.applyinfo.base.applydept = temp.department
        this.getRoleLis(temp.id); //获取角色列表
      },
      //合并整理资源清单
      handleSpan(temp) {
        this.applyinfo.resourcesInfo.resourceInfo = []
        var _self = this.applyinfo.resourcesInfo.resourceInfo

        temp.forEach(item => {
          if (!item.check) {
            item.check = false
          }
          if (item.quantity === undefined) {
            item.quantity = 0
          }
          if (item.val) {
            if (item.resourcetype == 4 && typeof item.val === 'string') {
              item.quotaValue = JSON.parse(item.val)
              item.val = JSON.parse(item.val)
            } else if ((item.resourcetype == 0 || item.resourcetype == 6 || item.resourcetype == 5) &&
              typeof item
              .val ===
              'string') {
              item.quotaValue = parseInt(item.val)
              item.val = parseInt(item.val)
            } else {
              item.quotaValue = item.val
            }
            item.quotaUnit = item.unit
          } else {
            if (item.resourcetype == 4) {
              item.val = []
            } else {
              item.val = null
            }
          }
          var clazz = item.clazz
          if (_self.length === 0) {
            _self.push({
              'resourceName': clazz,
              'list': [item],
              check: item.check ? true : false
            })
          } else {
            var service = _self.find(e => e.resourceName == clazz)
            if (service) {
              if (item.check) {
                service.check = true
              }
              service.list.push(item)
            } else {
              _self.push({
                'resourceName': clazz,
                'list': [item],
                check: item.check ? true : false
              })
            }
          }
        })
      },

      chenckList() {
        if (this.getInfo() == "") {
          this.$Message.error("请至少填写一种资源申请!")
          return false
        } else {
          return true
        }
      },
      getPeopleAccount() {
        console.log("--getPeopleAccount------",this.toolInfo,this.applyinfo);
        if (this.applyinfo.remark.entrySysId != undefined && this.applyinfo.remark.entrySysId != null
          && this .applyinfo .remark.entrySysId > 0) {
          var accountList = [];
          var idList = [];
          this.toolInfo.toolList.forEach(item => {
              item.toolList.forEach(value => {
                if (value.check) {
                  var temp = {
                    id:value.templateAccountId,
                    serviceId:value.id,
                    serviceName:value.toolName,
                    isTool:true,
                    isRes:false,
                  };
                  accountList.push(temp);
                  value.needResources.forEach(val=>{
                    if (val.modelName == value.defaultResourcesModel) {
                      var temp = {
                        id:val.templateAccountId,
                        serviceId:val.id,
                        serviceName:val.subName,
                        isTool:true,
                        isRes:false
                      };
                      accountList.push(temp);
                    }
                  })
                }
              })
          })

          if (this.applyinfo.resourcesInfo.resourceInfo != undefined && this.applyinfo.resourcesInfo.resourceInfo !=
            null && this.applyinfo.resourcesInfo.resourceInfo.length > 0) {
            this.applyinfo.resourcesInfo.resourceInfo.forEach(item => {
              if (item.check) {
                console.log("-s--",this.applyinfo.resourcesInfo.resourceInfo);
                item.list.forEach(value=>{
                  if(value.check){
                    var temp = {
                      id:value.templateAccountId,
                      serviceId:value.id,
                      serviceName:value.subName,
                      isTool:true,
                      isRes:false
                    };
                    accountList.push(temp);
                  }
                })
              }
            })
          }

          this.$refs.account.setAccount(this.applyinfo.remark.entrySysId,accountList);
          // if(!this.ifedit){
          //   this.$refs.account.setAccount(this.applyinfo.remark.entrySysId,accountList);
          // }else{
          //   this.$refs.account.getRemoveId(this.applyinfo.remark.entrySysId,accountList);
          // }
        }
      },
      setPeopleAccount(accountList) {
        console.log("--setPeopleAccount---",accountList);
        var result = {
          severs: [],
          dbs: [],
          hadoops: [],
          hftps: [],
          paas: [],
          dacps: [],
          elseAuthes: []
        };

        accountList.forEach(item => {
          if (item.accountPeopleEntity.severs != undefined && item.accountPeopleEntity.severs != null && item.accountPeopleEntity.severs.length > 0) {
            item.accountPeopleEntity.severs.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.severs = result.severs.concat(item.accountPeopleEntity.severs);
          }

          if (item.accountPeopleEntity.dbs != undefined && item.accountPeopleEntity.dbs != null && item.accountPeopleEntity.dbs.length > 0) {
            item.accountPeopleEntity.dbs.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.dbs = result.dbs.concat(item.accountPeopleEntity.dbs);
          }

          if (item.accountPeopleEntity.hadoops != undefined && item.accountPeopleEntity.hadoops != null && item.accountPeopleEntity.hadoops.length > 0) {
            item.accountPeopleEntity.hadoops.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.hadoops = result.hadoops.concat(item.accountPeopleEntity.hadoops);
          }

          if (item.accountPeopleEntity.hftps != undefined && item.accountPeopleEntity.hftps != null && item.accountPeopleEntity.hftps.length > 0) {
            item.accountPeopleEntity.hftps.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.hftps = result.hftps.concat(item.accountPeopleEntity.hftps);
          }

          if (item.accountPeopleEntity.paas != undefined && item.accountPeopleEntity.paas != null && item.accountPeopleEntity.paas.length > 0) {
            item.accountPeopleEntity.paas.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.paas = result.paas.concat(item.accountPeopleEntity.paas);
          }

          if (item.accountPeopleEntity.dacps != undefined && item.accountPeopleEntity.dacps != null && item.accountPeopleEntity.dacps.length > 0) {
            item.accountPeopleEntity.dacps.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.dacps = result.dacps.concat(item.accountPeopleEntity.dacps);
          }

          if (item.accountPeopleEntity.elseAuthes != undefined && item.accountPeopleEntity.elseAuthes != null && item.accountPeopleEntity.elseAuthes.length > 0) {
            item.accountPeopleEntity.elseAuthes.forEach(value=>{
              value.serviceName = item.serviceName;
            })
            result.elseAuthes = result.elseAuthes.concat(item.accountPeopleEntity.elseAuthes);
          }
        })

        return result;
      },
      /**
       * 提交-获取提交表单信息并加以处理
       */
      getInfo() {
        var temp = this.applyinfo
        var info = {
          base: {},
          projectInfo: {},
          resources: [],
          severs: [],
          tools: [],
          datas: [],
          files: [],
          account: {},
          remark: {},
        }

        info.base = temp.base
        info.base.dptName = this.applyinfo.base.applydept
        info.projectInfo = temp.projectInfo
        info.remark = temp.remark
        info.severs = []

        //设置物理机
        this.seversList.forEach(item => {
          if (!item.check && !item.disabled) {
            if (!item.forToolServiceIds) {
              item.forToolServiceIds = []
            }
            info.severs.push(item)
          }
        })
        // info.datas = temp.datas
        info.files = temp.files

        var accountList = {
          people: []
        }
        if (temp.account.people.length > 0) {
          temp.account.people.forEach(item => {
            if (item.peopleName != '') {
              if (typeof item.peopleUserId != 'number') {
                item.peopleUserId = 0
              }
            }
            accountList.people.push(item)
          })
        }
        var result = this.setPeopleAccount(this.$refs.account.account);
        if (result != undefined && result != null) {
          accountList.people.forEach(item => {
            item.severs = result.severs;
            item.dbs = result.dbs;
            item.hadoops = result.hadoops;
            item.hftps = result.hftps;
            item.paas = result.paas;
            item.dacps = result.dacps;
            item.elseAuthes = result.elseAuthes;
          })
        }
        info.account = accountList

        //处理resourceList
        var resourceList = temp.resourcesInfo.resourceInfo
        resourceList.forEach(item => {
          if (item.check) {
            item.list.forEach(list => {
              if (list.check) {
                var t1 = JSON.stringify(list)
                var t2 = JSON.parse(t1)
                if (t2.resourcetype == 4) {
                  t2.val = JSON.stringify(list.val)
                }
                if (t2.serviceId == undefined || t2.serviceId == null) {
                  t2.serviceId = list.id
                }
                info.resources.push(t2)
              }
            })
          }
        })


        //处理工具
        info.tools = this.getTool()
        var publicInfo = this.utils.setPublicInfoInfo(this.applyinfo.reqSubject, 0, 0, temp.projectInfo.projectDoc)
        var submits = {
          base: {
            roleId: temp.projectInfo.roleId,
            projectId: temp.projectInfo.projectId
          },
          object: info,
          files: info.files,
          puslicInfo: publicInfo
        }
        return submits;
      },

      /**
       * 提交——处理工具信息
       */
      getTool() {
        var temp = []
        this.toolInfo.toolList.forEach(toolList => {
          toolList.toolList.forEach(item => {
            if (item.check) {
              var resourceTemp = []
              var t1 = JSON.stringify(item)
              var t2 = JSON.parse(t1)
              if (t2.needResources) {
                if (item.spServiceType == 'dataEtl') {
                  t2.needResources.forEach(i => {
                    if (!t2.default) {
                      t2.val = t2.quotaValue
                      t2.unit = t2.quotaUnit
                    }
                    if (t2.resourcetype == 4) {
                      t2.val = JSON.stringify(t2.val)
                      t2.quotaValue = JSON.stringify(t2.quotaValue)
                    }
                  })
                } else {
                  var seversTemp = []
                  // 获取选择的套餐
                  if(t2.packageLists){
                    t2.packageLists.forEach(packages => {
                      if (t2.defaultResourcesModel == packages.modelName) {
                        packages.package.toolServiceList.forEach(tool => {
                          t2.customResources = t2.default
                          if (!t2.default) {
                            tool.val = tool.quotaValue
                            tool.unit = tool.quotaUnit
                          }
                          if (tool.resourcetype == 4) {
                            tool.val = JSON.stringify(tool.val)
                            tool.quotaValue = JSON.stringify(tool.quotaValue)
                          }
                        })

                        seversTemp = packages.package.severs
                        resourceTemp = packages.package.toolServiceList
                      }
                    })
                  }

                  t2.resourcesPackage = t2.defaultResourcesModel
                  t2.needResources = resourceTemp
                  t2.needSevers = seversTemp
                }
              }
              if (t2.spContent) {
                if (t2.spServiceType == 'openApiPlatform') {
                  if (t2.spContent.hasAccount == 1) {
                    t2.spContent.hasAccount = true
                  } else {
                    t2.spContent.hasAccount = false
                  }
                  t2.spContent.datas.forEach(datas =>{
                    this.$delete(datas,'ifCheck')
                    this.$delete(datas,'apiCodeori')
                  })
                } else if (t2.spServiceType == 'dataEtl') {
                  if (t2.spContent.ifNeedPublicData == true) {
                    t2.spContent.ifNeedPublicData = 1
                  } else {
                    t2.spContent.ifNeedPublicData = 0
                  }
                  if (t2.spContent.ifNeedPrivateData == true) {
                    t2.spContent.ifNeedPrivateData = 1
                  } else {
                    t2.spContent.ifNeedPrivateData = 0
                  }
                  t2.spContent.actTime = new Date(t2.spContent.actTime).getTime() / 1000
                  t2.spContent.privateTransmisMode = JSON.stringify(t2.spContent.privateTransmisMode)
                  t2.spContent.publicTransmisMode = JSON.stringify(t2.spContent.publicTransmisMode)
                }
              }
              temp.push(t2)
            }
          })
        })
        return temp
      },
      validate() {
        var isSubimt = false
        var isStep6 = false;

        if (!this.$refs.projectInfo.validate()) {
          this.stepTitleId = 0
        } else if (this.$refs.resoureceInfo.validate()) {
          this.stepTitleId = 1
        } else {
          isSubimt = true
          isStep6 = true
        }
        if (isSubimt) {
          var info = this.getInfo()
          if (info.object.datas.length == 0 && info.object.resources.length == 0 && info.object.tools.length == 0 &&
            this.seversList.length === 0) {
            this.$Message.error("请至少填写一种资源申请!")
            isSubimt = false
            isStep6 = false
          }
          if (info.object.tools.length > 0) {
            info.object.tools.forEach(tool => {
              if (tool.spServiceType == "dataEtl" && tool.spContent.ifNeedPublicData == 1) {
                if (!tool.spContent.dataFrequent) {
                  isSubimt = false
                  isStep6 = false
                  this.$refs.stepInfo.chlickStep(2)
                  this.$Message.error('请填写数据采集交换工具中的 “数据需求频率”');
                } else if (!tool.spContent.actTime) {
                  isSubimt = false
                  isStep6 = false
                  this.$refs.stepInfo.chlickStep(2)
                  this.$Message.error('请填写数据采集交换工具中的 “数据生效时间”');
                } else if (!tool.spContent.extDemand) {
                  isSubimt = false
                  isStep6 = false
                  this.$refs.stepInfo.chlickStep(2)
                  this.$Message.error('请填写数据采集交换工具中的 “抽样要求”');
                } else if (!tool.spContent.reqDes) {
                  isSubimt = false
                  isStep6 = false
                  this.$refs.stepInfo.chlickStep(2)
                  this.$Message.error('请填写数据采集交换工具中的 “需求描述”');
                }
              }
            })
          }
          if (info.object.account.people.length > 0) {
            info.object.account.people.some(item => {
              if (item.peopleName != undefined && item.peopleName != null && item.peopleName != "" && (item
                  .fourA ==
                  undefined || item.fourA == null || item.fourA == '')) {
                this.$Message.error("请至少填写【" + item.peopleName + "】的4A账号!")
                isSubimt = false
                isStep6 = false
                return true
              }
            })
          }
        }

        if (this.stepTitleId != 6 && isStep6) {
          this.$refs.stepInfo.chlickStep(6)
          this.$Modal.info({
            title: "温馨提示：",
            content: "请最终确认申请相关信息！"
          });
          isSubimt = false
        }

        return isSubimt
      },

      // 获取处理时需要提交的参数
      getHandleParams(handleInfo) {
        handleInfo.reqSubject = this.applyinfo.reqSubject
        handleInfo.startTime = 0
        handleInfo.hopeTime = 0
        handleInfo.reqDes = this.applyinfo.projectInfo.projectDoc
        handleInfo.isEdit = this.isEdit;
        handleInfo.isChangeContent = 0;
        if (!this.ifedit) {
          handleInfo.isChangeContent = 1;
        }
        if (this.isEdit == 1 || this.isEdit == 23) {
          handleInfo.roleId = this.applyinfo.projectInfo.roleId;
          handleInfo.projectId = this.applyinfo.projectInfo.projectId;
          handleInfo.content = this.getInfo()
        }
      },
      //处理页面获取下一步处理人需要的参数
      getHandleUserParams(opOptions) {
        var param = {}
        if (opOptions != "") {
          param.vari = opOptions
        }
        param.roleId = this.applyinfo.projectInfo.roleId;
        param.projectId = this.applyinfo.projectInfo.projectId;
        return param
      },

      //格式化日期
      formatDate(value) {
        var date = new Date(value * 1000);
        var year = date.getFullYear();
        var month = this.padDate(date.getMonth() + 1);
        var day = this.padDate(date.getDate());
        var hours = this.padDate(date.getHours());
        var minutes = this.padDate(date.getMinutes());
        var seconds = this.padDate(date.getSeconds());
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
      },
      padDate(value) {
        return value < 10 ? '0' + value : value;
      },
      formatTime(value) {
        return this.utils.formatDate(new Date(value * 1000), "yyyy-MM-dd")
      },
    },
    props: {
      isEdit: {},
      value: {
        default: false
      },
      ifedit: {
        type: Boolean,
        default: false,
      },
      reqId: {
        default: null
      },
      draftsId: {
        default: null
      },
      filesList: {},
      processInfo: {},
      ishidden: {
        type: Boolean,
        default: false,
      },
    },
    computed: {
      newValue: {
        get: function() {
          return this.value;
        },
        set: function(value) {
          this.$emit('input', value);
        }
      },
    },
    watch: {
      newValue(val) {
        if (val) {
          var base = this.myElement.getElement(this.baseId);
          this.printBaseInfo = base.object;
          this.baseInfoLength = base.length;

          var project = this.myElement.getElement(this.projectInfoId);
          this.printProject = project.object;
          this.projectInfoLength = project.length;
          this.print()
        }
      }
    },
  }
</script>
